Lab 26
Handle Graphics
CS211 Lab Policy:
- This lab exercise will not be graded.
- Submit as much as you have completed before the end of the lab period in
which it is assigned.
- If you do not finish this lab work, it is to your advantage to finish it
outside of class. Please re-submit your finished work to the course web
site.
- You may receive help from anyone in completing this lab.
- You may not submit another student's code as part of your
lab.
Instructions:
For this lab you will create and submit the program
Lab26() saved in the file
lab26.m. Add code to your lab26 program that does the
following tasks.
- Clear the command window.
- Plot sin(x) and
cos(x) on the interval x = -2π
to 2π. (Use
hold('on') and 2 calls to the
plot() function.) Capture the graphics
handle returned by each call to the plot()
function for each graphed line. These will be handles to line
objects.
- Use the get() function to get a
handle to the axes object the lines are graphed in. (Use the
parent property of either line.)
- Get and display all of the properties of an axes object. (Use the
get() command and display your
results using disp().) Examine the
structure array that contains the properties. Note that there are many
properties of an axes object!
- Get and display all of the properties of a line object. (Use the
get() command.) Notice that line
objects have different properties as compared to axes objects.
- In order to see the individual changes to your graph requested in the
following tasks, place a
waitforbuttonpress() function after each one. This will pause
your program until the user clicks a mouse button or presses a key on the
keyboard. Add a close() command at
the bottom of your Lab26() function
so that each time you run your program you will start with a new graph.
- Change the line object that graphs the sine curve to a red line of width 3.
(Change the 'color' and
'lineWidth' properties. For the color, you
can use the predefined color name 'red' or a
(red, green, blue) vector, [1 0 0]).
- Change the line graph of the cosine curve to a green line of
width 4. (For the color, you can use the predefined color name
'green' or a (red, green, blue) vector, [0 1
0]).
- Add vertical grid lines to the plot. (Use the 'xgrid'
property of the axes object. Its value can be 'on' or 'off'.)
- Add horizontal grid lines to the plot. (Use the
'ygrid' property of the axes object. Its value can be 'on' or 'off'.)
- Get the handle for the figure object that contains the axes
object. (Use the 'parent' property of the
axes object.) Then remove the figure number in the title bar and change the
figure name to "Sine and Cosine." In addition, change the figure background
color to purple ([1 0 1]). (Use the 'numberTitle',
'name', and 'color'
properties of the figure object.)
- Close the figure.
Please spend your remaining lab time working on
PEX 3.
Turn-in:
Submit your
Lab26.m file.